const IndexModel = require("../../model/home/indexModel.js")
class Index{
	/**
	 * @param {Object} ctx
	 * @description 获取首页 菜单接口
	 */
	static async getMenu(ctx){
		let res = await IndexModel.getMenu()
		ctx.body = {
			code:0,
			codeInfo:"成功",
			data:res
		}
	}
	
	/**
	 * @description 获取首页轮播图
	 * @param {Object} ctx
	 * @param {String} keyword 关键字
	 */
	static async getAdList(ctx){
		let {keyword} = ctx.request.query
		let res = await IndexModel.getad(keyword)
		ctx.body = {
			code:0,
			codeInfo:"成功",
			data:res
		}
	}
	
	// 获取商品列表
	static async getGoodsList(ctx){
		let {city,nowpage,pagesize} = ctx.request.query
		let res = await IndexModel.getGoods(city,nowpage,pagesize)
		ctx.body = {
			code:0,
			codeInfo:"成功",
			data:res
		}
	}
	
	// 获取商品详情
	static async getGoodsDetail(ctx){
		let {id} = ctx.request.query
		let res = await IndexModel.getGoodsDetail(id)
		if(res){
			ctx.body = {
				code:0,
				codeInfo:"成功",
				data:res
			}
		}else{
			ctx.body = {
				code:1,
				codeInfo:"该商品已经下架"
			}
		}
	}
	
	static async searchGoods(ctx){
		let {nowpage,pagesize,keyword} = ctx.request.query
		console.log({nowpage,pagesize,keyword},62)
		let res = await IndexModel.searchGoods(nowpage,pagesize,keyword)
		ctx.body = {
			code:0,
			codeInfo:"成功",
			data:res
		}
	}
}
module.exports =Index